package com.cswangdao.controller.admin;


import com.cswangdao.domain.dto.KeywordPageDTO;
import com.cswangdao.domain.model.MarketKeyword;
import com.cswangdao.result.PageResult;
import com.cswangdao.result.Result;
import com.cswangdao.service.KeywordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/keyword")
@RestController
@Slf4j
public class AdminKeywordController {

    @Autowired
    private KeywordService keywordService;

    @GetMapping("/list")
    public Result<PageResult<MarketKeyword>> list(KeywordPageDTO pageDTO) {
        log.info("关键字列表查询：{}",pageDTO);
        PageResult<MarketKeyword> pageResult = keywordService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/create")
    public Result<MarketKeyword> create(@RequestBody MarketKeyword keyword) {
       log.info("关键字创建：{}",keyword);
       keywordService.addKeyword(keyword);
       return Result.success(keyword);
    }

    @PostMapping("/update")
    public Result<MarketKeyword> update(@RequestBody MarketKeyword keyword)  {
        log.info("关键字更新：{}",keyword);
        keywordService.updateById(keyword);
        return Result.success(keyword);
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody MarketKeyword keyword)  {
        log.info("关键字删除：{}",keyword);
        keywordService.deleteById(keyword.getId());
        return Result.success();
    }

}
